package org.js.student.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.js.student.domain.ClassManage;
import org.js.student.service.IClassManageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 班级管理Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@RestController
@RequestMapping("/manage")
public class ClassManageController extends BaseController
{
    @Autowired
    private IClassManageService classManageService;

    /**
     * 查询班级管理列表
     */
    @RequiresPermissions("student:manage:list")
    @GetMapping("/list")
    public TableDataInfo list(ClassManage classManage)
    {
        startPage();
        List<ClassManage> list = classManageService.selectClassManageList(classManage);
        return getDataTable(list);
    }

    /**
     * 导出班级管理列表
     */
    @RequiresPermissions("student:manage:export")
    @Log(title = "班级管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassManage classManage)
    {
        List<ClassManage> list = classManageService.selectClassManageList(classManage);
        ExcelUtil<ClassManage> util = new ExcelUtil<ClassManage>(ClassManage.class);
        util.exportExcel(response, list, "班级管理数据");
    }

    /**
     * 导出班级管理列表
     */
    //@RequiresPermissions("student:manage:import")
    @PostMapping("/import")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<ClassManage> util = new ExcelUtil<ClassManage>(ClassManage.class);
        List<ClassManage> userList = util.importExcel(file.getInputStream());
        for (ClassManage classManage : userList) {
            classManageService.insertClassManage(classManage);
        }
        return AjaxResult.success();
    }


    /**
     * 获取班级管理详细信息
     */
    @RequiresPermissions("student:manage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(classManageService.selectClassManageById(id));
    }

    /**
     * 新增班级管理
     */
    @RequiresPermissions("student:manage:add")
    @Log(title = "班级管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassManage classManage)
    {
        return toAjax(classManageService.insertClassManage(classManage));
    }

    /**
     * 修改班级管理
     */
    @RequiresPermissions("student:manage:edit")
    @Log(title = "班级管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassManage classManage)
    {
        return toAjax(classManageService.updateClassManage(classManage));
    }

    /**
     * 删除班级管理
     */
    @RequiresPermissions("student:manage:remove")
    @Log(title = "班级管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classManageService.deleteClassManageByIds(ids));
    }
}
